package com.qch.listener;

import com.qch.config.RabitConfig;
import com.qch.pojo.OrderDO;
import com.qch.service.OrderService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author qch
 * @Date 2021/5/20
 */
@Component
public class MyOrderListener {
    @Autowired
    private OrderService orderService;
    @RabbitListener(queues = "dlx.order.queue")
    public void onMessage(String orderId){
        OrderDO orderDO = orderService.queryByOrderId(orderId);
        if(orderDO.getStatus().equals("待支付"))//订单状态为已超时
        {
            orderDO.setUpdateAt(new Date());
            orderDO.setStatus("超时已取消");
            orderService.update(orderDO);
            System.out.println("超时订单为"+orderId);
        }

    }
}
